<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.model.User"%>

<script type="text/javascript">
<!--
	$(document).ready(function() {
		$("#editFormatDefinitionDiv").dialog({
			title : '<%=UserUtil.getCurrentMenuItemName() %>',
			width : 700,
			resizable : false,
			modal : true
		});

		$("#editComissionBtn").click(function() {			
			$('#editmethod').attr('name','toEditComission');			
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : 	$("#editHiddenForm").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					//$("#editCommissionCodeTableDiv").dialog("destroy");
					$("#editCommissionCodeTableDiv").html(data);
					$("#editCommissionCodeTableDiv").dialog({
						title : '手續費代碼清單',
						width : 600,
						resizable : true,
						modal : true
					});
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});			
		});
		
		$("#editAppGroupBtn").click(function() {			
			$('#editmethod').attr('name','toEditAppGroup');


			var groupNo = $('#editFormatDefinition\\.group\\.groupNo').val();

			$('#hidden\\.editFormatDefinition\\.group\\.groupNo').val(groupNo);
						
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : 	$("#editHiddenForm").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					//$("#editCommissionCodeTableDiv").dialog("destroy");
					$("#editCommissionCodeTableDiv").html(data);
					$("#editCommissionCodeTableDiv").dialog({
						title : '帳務處理費設定',
						width : 600,
						resizable : true,
						modal : true
					});
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});			
		});
		
		$("#editAppGroupPostBtn").click(function() {			
			$('#editmethod').attr('name','toEditAppGroupPost');
            

			var groupNo = $('#editFormatDefinition\\.group\\.groupNo').val();

			$('#hidden\\.editFormatDefinition\\.group\\.groupNo').val(groupNo);
						
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : 	$("#editHiddenForm").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					//$("#editCommissionCodeTableDiv").dialog("destroy");
					$("#editCommissionCodeTableDiv").html(data);
					$("#editCommissionCodeTableDiv").dialog({
						title : '郵局代收手續費設定',
						width : 520,
						resizable : true,
						modal : true
					});
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});			
		});
		
		$("#cancelEditFormatDefinitionBtn").click(function() {
			
			$("#editFormatDefinitionDiv").dialog("close");
		});
		
		$("#deleteBtn").click(function() {
			var answer = confirm('是否確定刪除 ?');
        	
        	if (!answer)
        		return ;
        	
        	var formatDefinitionPk = $('#editFormatDefinition\\.formatDefinitionPk').val();
			
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : {doAjaxDelete: 'doAjaxDelete', 'editFormatDefinition.formatDefinitionPk': formatDefinitionPk},
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					$("#ajaxErrorMessageDiv").html(data);
					$("#ajaxErrorMessageDiv").dialog({
						title : '<%=UserUtil.getCurrentMenuItemName() %>',
						width : 300,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								if (1==$("#doAjaxDeleteResultCode").val()){
									doQueryAction();
									$("#editFormatDefinitionDiv").dialog("close");
								}
								$(this).dialog("close");
							}
						}
					});
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					//$("#ajaxErrorMessageDiv").dialog("destroy");
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
		});
		
		
		$("#saveBtn").click(function() {
			var pk = $('#editFormatDefinition\\.formatDefinitionPk').val();
			var groupNo = $('#editFormatDefinition\\.group\\.groupNo').val();
			var formatName = $('#editFormatDefinition\\.formatName').val();
			var formatType = $('#editFormatDefinition\\.formatType').val();
			var jrxmlPath = $('#editFormatDefinition\\.jrxmlPath').val();
			var customValidateClass = $('#editFormatDefinition\\.customValidateClass').val();
			
			var deleted = $('#editFormatDefinition\\.deleted').attr("checked");

			
			var errMsg = "";
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號 是必要欄位<br/>";
			}
			
			if (null == formatName || 0 == formatName.length){
				errMsg = errMsg + "項目名稱 是必要欄位<br/>";
			}			
			
			if (null == formatType || 0 == formatType.length){
				errMsg = errMsg + "類別 是必要欄位<br/>";
			}
			else if ('2' != formatType){
				if (null == jrxmlPath || 0 == jrxmlPath.length){
					errMsg = errMsg + "繳費單原始檔路徑 是必要欄位<br/>";
				}
			}
			
			
			
			//if (null == customValidateClass || 0 == customValidateClass.length){
			//	errMsg = errMsg + "客製化檢核類別名稱 是必要欄位<br/>";
			//}
			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			
			
			$('#hidden\\.editFormatDefinition\\.formatDefinitionPk').val(pk);
			$('#hidden\\.editFormatDefinition\\.group\\.groupNo').val(groupNo);
			$('#hidden\\.editFormatDefinition\\.formatName').val(formatName);
			$('#hidden\\.editFormatDefinition\\.jrxmlPath').val(jrxmlPath);
			$('#hidden\\.editFormatDefinition\\.formatType').val(formatType);
			$('#hidden\\.editFormatDefinition\\.customValidateClass').val(customValidateClass);
			$('#hidden\\.editFormatDefinition\\.deleted').val(deleted);

			doSaveFormateDefinitionAction();
		});
		
		function doSaveFormateDefinitionAction() {			
			
			$('#editmethod').attr('name', 'doAjaxSave');
			
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : 	$("#editHiddenForm").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {
					$("#ajaxErrorMessageDiv").html(data);
					$("#ajaxErrorMessageDiv").dialog({
						title : '<%=UserUtil.getCurrentMenuItemName() %>',
						width : 300,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
								if (1==$("#doAjaxSaveResultCode").val()){
									
									if (1==$("#continueEditCommission").val()){
										var fpk = $("#doAjaxSaveFormatDefinitionPk").val();
										$('#editFormatDefinition\\.formatDefinitionPk').val(fpk);
										$('#hidden\\.editFormatDefinition\\.formatDefinitionPk').val(fpk);
										$("#editComissionBtn").show();
										$("#editAppGroupBtn").show();
										$("#editAppGroupPostBtn").show();
									}
									else{
										
										$("#editFormatDefinitionDiv").dialog("close");
									
										var groupNo = $('#hidden\\.editFormatDefinition\\.group\\.groupNo').val();
										
										$('#hidden\\.qryFormatDefinition\\.group\\.groupNo').val(groupNo);
										doQueryAction();
									}
									
								}
							}
						}
					});
					
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
		}
		
		$('#editFormatDefinition\\.formatType').change(function() {
			doFormatTypeChange();
		});
		
				
		$('#printBtn3').click(function() {
			divPrint('editFormDiv');
		});
		
		$('#findGroupNoImg1').click(function() {
			$('#hidden\\.queryGroupTrigger').val('2');
			$('#hidden\\.qryGroup\\.groupNo').val('');
			$('#hidden\\.qryGroup\\.groupName').val('');
			$('#qryGroup\\.groupNo').val('');
			$('#qryGroup\\.groupName').val('');
			$("#queryGroupResultDiv").html('');
			
			$("#findGroupDiv" ).dialog( "destroy" );
			$("#findGroupDiv" ).dialog({  
				title:'帳單業者查詢' 
				, width: 600
				, resizable: true
				, modal: true
			});
		});
		
	});
//-->
</script>
<div id="editFormatDefinitionFormDiv">
	<stripes:form id="editFormatDefinition" name="editFormatDefinition" 
		beanclass="com.feib.soeasy.action.Soez9008ActionBean" method="post" onsubmit="javascript: return false;">
	
	<table id="queryForm">
		<tr>
			<td colspan="4" style="color: #990000">
				<strong>
					<c:choose>
						<c:when test="${null == actionBean.editFormatDefinition.formatDefinitionPk }">帳單項目新增</c:when>
						<c:otherwise>帳單項目修改</c:otherwise>
					</c:choose> 
				</strong>
				<stripes:hidden id="editFormatDefinition.formatDefinitionPk" name="editFormatDefinition.formatDefinitionPk" />
			</td>
		</tr>
		
		<tr>
			<th>業者代號<span id="mustKeyInStar">**</span></th>
			<td>
				<c:choose>
					<c:when test="${null == actionBean.editFormatDefinition.formatDefinitionPk }">
						<div id="findGroupNoImg1"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
						<stripes:text id="editFormatDefinition.group.groupNo" name="editFormatDefinition.group.groupNo" size="12" maxlength="12" readonly="true"/>
					</c:when>
					<c:otherwise>
						<c:out value="${actionBean.editFormatDefinition.group.groupNo }"/>
						<stripes:hidden id="editFormatDefinition.group.groupNo" name="editFormatDefinition.group.groupNo" />
					</c:otherwise>
				</c:choose>
			</td>
            <th>業者名稱</th>
            <td>
            	<span id="editFormatDefinition.group.groupName.span"><c:out value="${actionBean.editFormatDefinition.group.groupName }"/></span>                               
            </td> 
		</tr>
		
		<tr>
			<th>項目名稱<span id="mustKeyInStar">**</span></th>
			<td>
				<stripes:text id="editFormatDefinition.formatName" name="editFormatDefinition.formatName" size="40" maxlength="50"/>
			</td>
			<th>類別<span id="mustKeyInStar">**</span></th>
			<td>
				<c:choose>
					<c:when test="${null == actionBean.editFormatDefinition.formatType }">
						<stripes:select id="editFormatDefinition.formatType" name="editFormatDefinition.formatType">
							<stripes:option value="" label="--請選擇--"/>
						</stripes:select>
					</c:when>
					<c:otherwise>
						<stripes:hidden id="editFormatDefinition.formatType" name="editFormatDefinition.formatType" value="${actionBean.editFormatDefinition.formatType}" />
						<c:choose>
							<c:when test="${2 != actionBean.editFormatDefinition.formatType }">繳費單</c:when>
							<c:otherwise>繳款人</c:otherwise>
						</c:choose>
					</c:otherwise>
				</c:choose> 
			</td>
		</tr>
		
		<tr id="tr.editFormatDefinition.jrxmlPath" <c:if test="${2 == actionBean.editFormatDefinition.formatType }">style="display: none;"</c:if>  >
			<th>繳費單原始檔路徑<span id="mustKeyInStar">**</span></th>
			<td colspan="3">
				<stripes:text id="editFormatDefinition.jrxmlPath" name="editFormatDefinition.jrxmlPath" size="40" maxlength="50"/>
			</td>
		</tr>
		<tr id="tr.editFormatDefinition.customValidateClass" <c:if test="${2 == actionBean.editFormatDefinition.formatType }">style="display: none;"</c:if>  >
			<th>客製化檢核類別名稱</th>
			<td colspan="3">
				<stripes:text id="editFormatDefinition.customValidateClass" name="editFormatDefinition.customValidateClass" size="40" maxlength="50"/>
				<span> <font color="red">若無需客製化，則為空白</font></span>			
			</td>
		</tr>
		<tr>
	      <th>停用</th>
	      <td>
	      	<input type="checkbox" id="editFormatDefinition.deleted" name="editFormatDefinition.deleted" value="true" <c:if test="${actionBean.editFormatDefinition.deleted }">checked="checked"</c:if> class="chk" />
	      </td>
		</tr>
		
		<tr>
			<td colspan="4" class="queryFunction">
				<input type="button" id="saveBtn" value="確認" />
				<c:if test="${not actionBean.editFormatDefinition.batchUsed }">	
					<c:if test="${null != actionBean.editFormatDefinition.formatDefinitionPk }">						
						<input type="button" id="deleteBtn" value="刪除"/>
					</c:if>
				</c:if>
											
				<c:choose>
					<c:when test="${1 == actionBean.editFormatDefinition.formatType && null != actionBean.editFormatDefinition.formatDefinitionPk }">
						<input type="button" id="editComissionBtn" name="toEditComission" value="超商代碼設定" />
						<input type="button" id="editAppGroupPostBtn" name="toEditAppGroupPost" value="郵局手續費設定" />
						<input type="button" id="editAppGroupBtn" name="toEditAppGroup" value="帳務處理費設定" />						
					</c:when>
					<c:when test="${null == actionBean.editFormatDefinition.formatDefinitionPk }">
						<input type="button" id="editComissionBtn" name="toEditComission" value="超商代碼設定" style="display: none;"/>
						<input type="button" id="editAppGroupPostBtn" name="toEditAppGroupPost" value="郵局手續費設定" style="display: none;"/>
						<input type="button" id="editAppGroupBtn" name="toEditAppGroup" value="帳務處理費設定" style="display: none;"/>						
					</c:when>					
				</c:choose>				
				
				<input type="button" id="cancelEditFormatDefinitionBtn" value="離開" />
			</td>
		</tr>
	</table>
</stripes:form>

<div id="editHiddenFormDiv" style="display: none;">
	<stripes:form id="editHiddenForm" beanclass="com.feib.soeasy.action.Soez9008ActionBean" 
		method="post" onsubmit="javascript: return false;">
		<input type="hidden" id="hidden.editFormatDefinition.formatDefinitionPk" name="editFormatDefinition.formatDefinitionPk" value="<c:out value='${actionBean.editFormatDefinition.formatDefinitionPk }'/>" />		
		<input type="hidden" id="hidden.editFormatDefinition.formatName" name="editFormatDefinition.formatName" value="<c:out value='${actionBean.editFormatDefinition.group.groupName }'/>" />
		<input type="hidden" id="hidden.editFormatDefinition.group.groupNo" name="editFormatDefinition.group.groupNo" value="<c:out value='${actionBean.editFormatDefinition.group.groupNo }'/>" />
		<input type="hidden" id="hidden.editFormatDefinition.deleted" name="editFormatDefinition.deleted" value="" />
		<input type="hidden" id="hidden.editFormatDefinition.jrxmlPath" name="editFormatDefinition.jrxmlPath" value="" />
		<input type="hidden" id="hidden.editFormatDefinition.customValidateClass" name="editFormatDefinition.customValidateClass" value="" />
		<input type="hidden" id="hidden.editFormatDefinition.formatType" name="editFormatDefinition.formatType" value="" />
		
		<input type="hidden" id="editmethod" name="doSave"/>
	</stripes:form>
</div>
		
</div>

